package com.share.order.factory;

import com.share.common.core.domain.R;
import com.share.common.core.exception.ServiceException;
import com.share.order.api.RemoteOrderInfoService;
import com.share.order.domain.OrderInfo;
import com.share.order.domain.OrderSqlVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * 用户服务降级处理
 *
 * @author share
 */
@Component
public class RemoteOrderInfoFallbackFactory implements FallbackFactory<RemoteOrderInfoService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteOrderInfoFallbackFactory.class);

    @Override
    public RemoteOrderInfoService create(Throwable throwable)
    {
        return new RemoteOrderInfoService() {
            @Override
            public R<OrderInfo> getNoFinishOrder(Long userId) {
                return R.fail("获取未结束订单失败："+throwable.getMessage());
            }

            @Override
            public R<OrderInfo> getByOrderNo(String orderNo) {
                return R.fail("获取订单失败："+throwable.getMessage());
            }

            @Override
            public R<Map<String, Object>> getOrderCount(OrderSqlVo orderSqlVo) {
                return R.fail("获取订单报表失败："+throwable.getMessage());
            }
        };
    }
}
